﻿using System;
using System.Windows.Forms;
using DSkin.Controls;
using vdColorComboBox;
using vdLayersComboBox;
using vdLinetypeComboBox;
using vdLineWeightComboBox;
using VectorDraw.Professional.vdCollections;
using VectorDraw.Professional.vdPrimaries;

namespace ZhCAD
{
    public sealed partial class ToolbarStandard : DSkinToolStrip
    {
        private readonly ToolStripComboBox _activeFile;
        private readonly vdColorCombo _colorCombo;
        private vdSelection selection;
        private readonly vdLayersCombo _layersCombo;
        private readonly vdLinetypeCombo _linetypeCombo;
        private readonly vdLineWeightCombo _lineWeightCombo;
        private Childform _doc;

        public ToolbarStandard()
        {
            _activeFile = new ToolStripComboBox {DropDownStyle = ComboBoxStyle.DropDownList};
            _activeFile.SelectedIndexChanged += ActiveFile_SelectedIndexChanged;

            _layersCombo = new vdLayersCombo();
            _colorCombo = new vdColorCombo();
            _linetypeCombo = new vdLinetypeCombo();
            _lineWeightCombo = new vdLineWeightCombo();
            Items.Add(new ToolStripLabel {Text = "当前文件"});
            Items.Add(_activeFile);
            Items.Add(new ToolStripControlHost(_layersCombo));
            Items.Add(new ToolStripControlHost(_colorCombo));
            Items.Add(new ToolStripControlHost(_linetypeCombo));
            Items.Add(new ToolStripControlHost(_lineWeightCombo));
        }

        public Childform DocForm
        {
            get => _doc;
            set
            {
                _doc = value;
                _layersCombo.LayersDocument = _doc.Document;
                _colorCombo.ColorDocument = _doc.Document;
                _linetypeCombo.LinetypesDocument = _doc.Document;
                _lineWeightCombo.LineWeightDocument = _doc.Document;
                _activeFile.ComboBox.DataSource = _doc.Filelist.GetFiles();
                _activeFile.SelectedIndex = 0;
                selection = _doc.Document.GetGripSelection();
                selection.RaiseOnUserChanged();
                //activeFile.ComboBox.DisplayMember = "Filename";
            }
        }


        private void ActiveFile_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selection == null) return;
            if (selection.Count == 0)
            {
                _doc.ActiveFile = _activeFile.SelectedItem.ToString();
            }
            else
            {
                foreach (vdFigure figure in selection)
                {
                    
                }
            }
            
        }
    }
}